/**
 * <copyright>
 * </copyright>
 *
 * $Id: JVMImpl.java,v 1.1 2008/11/09 03:11:52 song Exp $
 */
package cn.edu.pku.sei.ra.wrapping.JOnAS.impl;

import javax.management.Attribute;
import javax.management.ObjectName;
import javax.management.j2ee.Management;

import cn.edu.pku.sei.ra.wrapping.JOnAS.JOnASPackage;
import cn.edu.pku.sei.ra.wrapping.JOnAS.JVM;
import cn.edu.pku.sei.ra.wrapping.JOnAS.MBeanServer;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>JVM</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.JVMImpl#getJavaVersion <em>Java Version</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.JVMImpl#getJavaVendor <em>Java Vendor</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.JVMImpl#getAllThreadCount <em>All Thread Count</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.JVMImpl#getParent <em>Parent</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class JVMImpl extends J2EEManagedObjectImpl implements JVM {
	/**
	 * The default value of the '{@link #getJavaVersion() <em>Java Version</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getJavaVersion()
	 * @generated
	 * @ordered
	 */
	protected static final String JAVA_VERSION_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getJavaVersion() <em>Java Version</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getJavaVersion()
	 * @generated
	 * @ordered
	 */
	protected String javaVersion = JAVA_VERSION_EDEFAULT;

	/**
	 * The default value of the '{@link #getJavaVendor() <em>Java Vendor</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getJavaVendor()
	 * @generated
	 * @ordered
	 */
	protected static final String JAVA_VENDOR_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getJavaVendor() <em>Java Vendor</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getJavaVendor()
	 * @generated
	 * @ordered
	 */
	protected String javaVendor = JAVA_VENDOR_EDEFAULT;

	/**
	 * The default value of the '{@link #getAllThreadCount() <em>All Thread Count</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAllThreadCount()
	 * @generated
	 * @ordered
	 */
	protected static final int ALL_THREAD_COUNT_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getAllThreadCount() <em>All Thread Count</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAllThreadCount()
	 * @generated
	 * @ordered
	 */
	protected int allThreadCount = ALL_THREAD_COUNT_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected JVMImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return JOnASPackage.Literals.JVM;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getJavaVersion() {
        if(getCore()==null) 
        	return "";
		
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			Object res=mainEntry.getAttribute(obj, "javaVersion");
			
			javaVersion=res.toString();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
        
		return javaVersion;//second
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setJavaVersion(String newJavaVersion) {
		String oldJavaVersion = javaVersion;
		javaVersion = newJavaVersion;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.JVM__JAVA_VERSION, oldJavaVersion, javaVersion));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getJavaVendor() {
        if(getCore()==null) 
        	return "";
		
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			Object res=mainEntry.getAttribute(obj, "javaVendor");
			
			javaVendor=res.toString();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
        
		return javaVendor;//second
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setJavaVendor(String newJavaVendor) {
		String oldJavaVendor = javaVendor;
		javaVendor = newJavaVendor;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.JVM__JAVA_VENDOR, oldJavaVendor, javaVendor));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public int getAllThreadCount() {
        if(getCore()==null) 
        	return  -1;
		
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			Object res=mainEntry.getAttribute(obj, "allThreadsCount");
			
			allThreadCount=((Integer)res).intValue();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
        
		return allThreadCount;//second
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAllThreadCount(int newAllThreadCount) {
		int oldAllThreadCount = allThreadCount;
		allThreadCount = newAllThreadCount;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.JVM__ALL_THREAD_COUNT, oldAllThreadCount, allThreadCount));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public MBeanServer getParent() {
		if (eContainerFeatureID != JOnASPackage.JVM__PARENT) return null;
		return (MBeanServer)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetParent(MBeanServer newParent, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newParent, JOnASPackage.JVM__PARENT, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParent(MBeanServer newParent) {
		if (newParent != eInternalContainer() || (eContainerFeatureID != JOnASPackage.JVM__PARENT && newParent != null)) {
			if (EcoreUtil.isAncestor(this, newParent))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newParent != null)
				msgs = ((InternalEObject)newParent).eInverseAdd(this, JOnASPackage.MBEAN_SERVER__JVM, MBeanServer.class, msgs);
			msgs = basicSetParent(newParent, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.JVM__PARENT, newParent, newParent));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case JOnASPackage.JVM__PARENT:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetParent((MBeanServer)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case JOnASPackage.JVM__PARENT:
				return basicSetParent(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID) {
			case JOnASPackage.JVM__PARENT:
				return eInternalContainer().eInverseRemove(this, JOnASPackage.MBEAN_SERVER__JVM, MBeanServer.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case JOnASPackage.JVM__JAVA_VERSION:
				return getJavaVersion();
			case JOnASPackage.JVM__JAVA_VENDOR:
				return getJavaVendor();
			case JOnASPackage.JVM__ALL_THREAD_COUNT:
				return new Integer(getAllThreadCount());
			case JOnASPackage.JVM__PARENT:
				return getParent();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case JOnASPackage.JVM__JAVA_VERSION:
				setJavaVersion((String)newValue);
				return;
			case JOnASPackage.JVM__JAVA_VENDOR:
				setJavaVendor((String)newValue);
				return;
			case JOnASPackage.JVM__ALL_THREAD_COUNT:
				setAllThreadCount(((Integer)newValue).intValue());
				return;
			case JOnASPackage.JVM__PARENT:
				setParent((MBeanServer)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case JOnASPackage.JVM__JAVA_VERSION:
				setJavaVersion(JAVA_VERSION_EDEFAULT);
				return;
			case JOnASPackage.JVM__JAVA_VENDOR:
				setJavaVendor(JAVA_VENDOR_EDEFAULT);
				return;
			case JOnASPackage.JVM__ALL_THREAD_COUNT:
				setAllThreadCount(ALL_THREAD_COUNT_EDEFAULT);
				return;
			case JOnASPackage.JVM__PARENT:
				setParent((MBeanServer)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case JOnASPackage.JVM__JAVA_VERSION:
				return JAVA_VERSION_EDEFAULT == null ? javaVersion != null : !JAVA_VERSION_EDEFAULT.equals(javaVersion);
			case JOnASPackage.JVM__JAVA_VENDOR:
				return JAVA_VENDOR_EDEFAULT == null ? javaVendor != null : !JAVA_VENDOR_EDEFAULT.equals(javaVendor);
			case JOnASPackage.JVM__ALL_THREAD_COUNT:
				return allThreadCount != ALL_THREAD_COUNT_EDEFAULT;
			case JOnASPackage.JVM__PARENT:
				return getParent() != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (javaVersion: ");
		result.append(javaVersion);
		result.append(", javaVendor: ");
		result.append(javaVendor);
		result.append(", allThreadCount: ");
		result.append(allThreadCount);
		result.append(')');
		return result.toString();
	}

} //JVMImpl
